package day9.homework;

import java.util.Scanner;

import day9.Student;

public class StudentDemo{

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		System.out.println("请输入学生数量");
		int count = scanner.nextInt();
		Student[] array = new Student[count];
		for (int i = 0; i < array.length; i++) {
			System.out.println("请输入学生id:");
			int id = scanner.nextInt();
			System.out.println("请输入学生姓名:");
			String name = scanner.next();
			System.out.println("请输入学生年龄:");
			int age = scanner.nextInt();
			System.out.println("请输入学生性别：");
			String gender = scanner.next();
			
//			Student student = new Student();
//			student.setId(id);
//			student.setName(name);
//			student.setAge(age);
//			student.setGender(gender);
			
			Student Student = new Student(id, name, age, gender);
			array[i] = Student;
		}
		for (int i = 0; i < array.length; i++) {
//			Student stu = array[i];
//			System.out.println(stu);
			System.out.println(array[i]);
		}

//	System.out.println("根据id搜索输入：1");
//	System.out.println("根据name搜索输入：2");
//	System.out.println("根据age搜素输入：3");
//	System.out.println("根据gender搜素输入：4");
//	System.out.println("退出程序输入：0");

	while (true) {
		System.out.println("根据id搜索输入：1");
		System.out.println("根据name搜索输入：2");
		System.out.println("根据age搜素输入：3");
		System.out.println("根据gender搜素输入：4");
		System.out.println("退出程序输入：0");
		int type = scanner.nextInt();
		if (type == 0) {
			System.out.println("退出程序");
			break;
		}
		switch (type) {
		case 1:
			System.out.println("请输入id:");
			int id = scanner.nextInt();
			boolean isFind = false;
			for (int i = 0; i < array.length; i++) {
				Student student1 = array[i];
				if (student1.getId() == id) {
					System.out.println(student1);
					isFind = true;
				}
			}
			if (isFind == false) {
				System.out.println("没有id是"+id+"的学生");
			}
			break;
		case 2:
			System.out.println("请输入id:");
			String name = scanner.next();
			boolean isname = false;
			for (int i = 0; i < array.length; i++) {
				Student student1 = array[i];
				if (name.equals(student1.getName())) {
					System.out.println(student1);
					isname = true;
				}
			}
			if (isname == false) {
				System.out.println("没有name是"+name+"的学生");
			}
			break;

		case 3:
			System.out.println("请输入id:");
			int age = scanner.nextInt();
			boolean isage = false;
			for (int i = 0; i < array.length; i++) {
				Student student1 = array[i];
				if (student1.getAge() == age) {
					System.out.println(student1);
					isage = true;
				}
			}
			if (isage == false) {
				System.out.println("没有age是"+age+"的学生");
			}
			break;
		case 4:
			System.out.println("请输入id:");
			String gender = scanner.next();
			boolean isgentder = false;
			for (int i = 0; i < array.length; i++) {
				Student student1 = array[i];
				if (gender.equals(student1.getGender())) {
					System.out.println(student1);
					isgentder = true;
				}
			}
			if (isgentder == false) {
				System.out.println("没有gender是"+gender+"的学生");
			}
			break;
		default:
			break;
		}
	}
	}
}
	
//	int a=0;//记录正数的个数
//	         int b=0;//记录负数的个数
//	         Scanner s=new Scanner(System.in);
//	         while(true){
//	             System.out.println("请输入一个整数");
//	             int sum=s.nextInt();
//	            if(sum>0)
//	                a++;
//	            else if (sum<0)
//	                 b++;
//	             else
//	                 break;
//	         }
//	 
//	        System.out.println("其中一共有"+a+"个正数；有"+b+"个负数");
//	     }
//	
//	
//	}
